﻿package mortal.game.view.common.display
{
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.display.*;
    import flash.geom.*;
    import mortal.common.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.Navbar.*;

    public class FlyToNavbarTool extends Object
    {
        public static const FlyToTime:Number = 0.6;

        public function FlyToNavbarTool()
        {
            return;
        }// end function

        public static function flyToBackPack(param1:BitmapData, param2:Point, param3:Function = null, param4:Boolean = true) : void
        {
            var _loc_5:GBitmap = null;
            if (!DisplayUtil.isBitmapDataUsable(param1))
            {
                return;
            }
            _loc_5 = UICompomentPool.getUICompoment(GBitmap) as GBitmap;
            _loc_5.bitmapData = param1.clone();
            _loc_5.x = param2.x;
            _loc_5.y = param2.y;
            _loc_5.width = 36;
            _loc_5.height = 36;
            LayerManager.topLayer.addChild(_loc_5);
            var _loc_6:* = (GameController.navbar.view as NavbarModule).getNavbarIconGlobalPoint(ModuleType.Pack);
            if (!param4)
            {
                TweenLite.to(_loc_5, FlyToTime, {x:_loc_6.x + 10, y:_loc_6.y + 10, onComplete:onComplete, onCompleteParams:[_loc_5, param3]});
            }
            else
            {
                TweenMax.to(_loc_5, FlyToTime, {x:_loc_6.x + 10, y:_loc_6.y + 10, bezier:[{x:_loc_6.x + 10, y:param2.y}], onComplete:onComplete, onCompleteParams:[_loc_5, param3]});
            }
            (GameController.navbar.view as NavbarModule).shakeIcon(ModuleType.Pack, FlyToTime);
            return;
        }// end function

        private static function onComplete(param1:GBitmap, param2:Function) : void
        {
            param1.dispose();
            if (param2 != null)
            {
                FlyToNavbarTool.param2();
            }
            return;
        }// end function

        public static function flyBitmapOriginalToPack(param1:BitmapData, param2:Point, param3:String = "pack") : void
        {
            if (!DisplayUtil.isBitmapDataUsable(param1) || param2 == null)
            {
                return;
            }
            var _loc_4:* = (GameController.navbar.view as NavbarModule).getNavbarIconGlobalPoint(param3);
            var _loc_5:* = param1.width;
            var _loc_6:* = param1.height;
            var _loc_7:* = 20 / Math.max(_loc_5, _loc_6);
            _loc_4.y = _loc_4.y + 10;
            _loc_4.x = _loc_4.x + 10;
            flyToAnyPoint(param1, param2, _loc_4, null, _loc_5, _loc_6, false, _loc_7, _loc_7, true, param3);
            return;
        }// end function

        public static function flyToAnyPoint(param1:BitmapData, param2:Point, param3:Point, param4:Function = null, param5:int = 0, param6:int = 0, param7:Boolean = true, param8:Number = 1, param9:Number = 1, param10:Boolean = true, param11:String = "pack") : void
        {
            if (!DisplayUtil.isBitmapDataUsable(param1))
            {
                if (param4 != null)
                {
                    param4.apply();
                }
                return;
            }
            var _loc_12:* = UICompomentPool.getUICompoment(GBitmap) as GBitmap;
            _loc_12.bitmapData = param1.clone();
            _loc_12.x = param2.x;
            _loc_12.y = param2.y;
            if (param5 != 0 && param6 != 0)
            {
                _loc_12.width = param5;
                _loc_12.height = param6;
            }
            LayerManager.topLayer.addChild(_loc_12);
            if (param10)
            {
                TweenMax.to(_loc_12, FlyToTime, {x:param3.x, y:param3.y, bezier:[{x:param3.x, y:param2.y}], scaleX:param8, scaleY:param9, onComplete:onFlyToAnyPointEnd, onCompleteParams:[_loc_12, param4, param7]});
            }
            else
            {
                TweenLite.to(_loc_12, FlyToTime, {x:param3.x, y:param3.y, scaleX:param8, scaleY:param9, onComplete:onFlyToAnyPointEnd, onCompleteParams:[_loc_12, param4, param7]});
            }
            if (param11 != null && param11 != "")
            {
                (GameController.navbar.view as NavbarModule).shakeIcon(param11, FlyToTime);
            }
            return;
        }// end function

        private static function onFlyToAnyPointEnd(param1:GBitmap, param2:Function, param3:Boolean) : void
        {
            if (param2 != null)
            {
                if (param1 != null)
                {
                    FlyToNavbarTool.param2(param1);
                }
            }
            if (param3)
            {
                param1.bitmapData.dispose();
            }
            param1.dispose();
            return;
        }// end function

        public static function flyToAnyPointPatch(param1:Array, param2:Array, param3:Point, param4:int = 0, param5:Number = 1, param6:String = "pack") : void
        {
            var _loc_7:BitmapData = null;
            var _loc_8:int = 0;
            var _loc_9:GBitmap = null;
            var _loc_10:Point = null;
            var _loc_11:int = 0;
            var _loc_12:int = 0;
            if (param1 == null)
            {
                return;
            }
            for each (_loc_7 in param1)
            {
                
                if (!DisplayUtil.isBitmapDataUsable(_loc_7))
                {
                    return;
                }
            }
            _loc_8 = 0;
            while (_loc_8 < param1.length)
            {
                
                _loc_9 = UICompomentPool.getUICompoment(GBitmap) as GBitmap;
                _loc_9.bitmapData = (param1[_loc_8] as BitmapData).clone();
                _loc_10 = param2[_loc_8];
                _loc_9.x = _loc_10.x;
                _loc_9.y = _loc_10.y;
                _loc_11 = (Math.random() - 0.5) * _loc_10.y * 0.7 + _loc_10.y;
                _loc_12 = (Math.random() - 0.5) * param3.x * 0.5 + param3.x;
                if (param4 != 0)
                {
                    _loc_9.width = param4;
                    _loc_9.height = param4;
                }
                LayerManager.topLayer.addChild(_loc_9);
                TweenMax.to(_loc_9, 0.6, {x:param3.x, y:param3.y, bezier:[{x:_loc_12, y:_loc_11}], scaleX:param5, scaleY:param5, onComplete:onFlyToAnyPointEnd, onCompleteParams:[_loc_9, null, true]});
                if (param6 != null && param6 != "")
                {
                    (GameController.navbar.view as NavbarModule).shakeIcon(param6, 0.6);
                }
                _loc_8++;
            }
            return;
        }// end function

    }
}
